import React from 'react'
import { list } from './list'
import { Row, Col } from 'antd'
import style from './index.module.scss'


export const listItem = (date = [], obj = {}, num = 1, styleRow = '', styleCol = '') => {
    let arr = []
    let ul = 0
    let start = 0   // 每段数组的开头
    const newSpan = Math.floor(24 / num);
    for (let i = num; i > 0; i--) {
        ul = Math.ceil((date.length - ul) / i)  // 每一列有多少个
        const newDate = date.slice(start, (start + ul)) //生成每一列新的数组
        start = start + ul; // 更新start
        arr.push(newDate)
    }
    // 填补空白
    for (let i = 1; i < arr.length; i++) {
        if (arr[i].length != arr[i - 1].length) {
            arr[i].push({
                id:Math.random(),
                name: "",
                key: ""
            })
        }

    }

    let newList = arr.map((item, index) => {
        return (<Col className={styleCol} span={newSpan} key={index}>
            {list(item, obj)}
        </Col>)
    })


    return (
        <div className={style.ListItem}>
            <Row className={styleRow}>
                {newList}
            </Row>
        </div>
    )
}
